//
//  LockUsersVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/13.
//  Copyright © 2020 tym. All rights reserved.
//

#import "MessageHistoryVC.h"
#import "OpenLockHistVC.h"
#import "UIView+ZJFrame.h"
#import "Sizes.h"
#import "UIView+ZFFrame.h"
#import "UnusualPoliceVC.h"
#import "NotBoundUserVC.h"
#import "OperationVC.h"
#import "ZJScrollPageView.h"
@interface MessageHistoryVC ()

@property(nonatomic,strong) ZJScrollPageView *scrollPageView;
@property(nonatomic,strong) OpenLockHistVC *familyVC;
@property(nonatomic,strong) UnusualPoliceVC *notBoundVC;

@property(nonatomic,strong) EquipmentModel *equipModel;
@property(nonatomic,strong) OperationVC *operVC;

@property(nonatomic,assign) NSInteger seleIndex;
@end

@implementation MessageHistoryVC

-(instancetype)initWithModel:(EquipmentModel*)model{
    self = [super init];
    self.equipModel = model;
    return self;
}

-(instancetype)initWithModel:(EquipmentModel*)model index:(NSInteger)index{
    self = [super init];
    self.equipModel = model;
    self.seleIndex = index;
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"消息记录"];
    self.view.zf_width = ScreenWidth;
    
    [self initScrollView];
}

-(void)backViewFunc:(id)btn{
   if (self.navigationController.viewControllers.count>1) {
        [super backViewFunc:btn];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

-(void)initScrollView{
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    style.titleFont = Font_Regular(16);
    style.selectedTitleFont = Font_Medium(16);
    style.showLine = YES;
    style.scrollLineHeight = 3;
    style.coverCornerRadius = 15;
    style.coverHeight = 30;
    style.scrollLineColor = [rgbaa(0,0,0,0) colorWithAlphaComponent:0];
    style.segmentHeight = 33;
    style.segmentViewBounces = NO;
    style.normalTitleColor = rgba(74, 74, 74);
    style.selectedTitleColor = rgba(74, 74, 74);
    style.contentViewBounces = NO;
    style.adjustCoverOrLineWidth = YES;
    style.autoAdjustTitlesWidth = YES;
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight - NavigateonHeight - SafeBottomMargin) segmentStyle:style titles:@[@"开锁记录",
    @"异常报警",@"操作日志"] parentViewController:self delegate:self];
    
    [scrollPageView bringSubviewToFront:scrollPageView.segmentView];
    scrollPageView.contentView.frame = CGRectMake(0,style.segmentHeight, self.view.bounds.size.width, scrollPageView.zj_height-style.segmentHeight);
    UIView *colorLine = [[UIView alloc] initWithFrame:CGRectZero];
    colorLine.backgroundColor = rgba(53, 54, 70);
    [scrollPageView.segmentView.scrollLine addSubview:colorLine];
    [colorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(scrollPageView.segmentView.scrollLine);
        make.size.mas_equalTo(CGSizeMake(14, 3.5));
    }];
    scrollPageView.segmentView.backgroundColor = [UIColor whiteColor];
    scrollPageView.contentView.backgroundColor = [UIColor whiteColor];
    scrollPageView.contentView.collectionView.backgroundColor = [UIColor whiteColor];
    scrollPageView.backgroundColor = [UIColor whiteColor];
    [scrollPageView setSelectedIndex:self.seleIndex?self.seleIndex:0 animated:NO];
    self.scrollPageView = scrollPageView;
    [self.view addSubview:self.scrollPageView];
}

-(OpenLockHistVC*)familyVC{
    if (_familyVC == nil) {
        _familyVC = [[OpenLockHistVC alloc] initWithModel:self.equipModel];
    }
    return _familyVC;
}

-(UnusualPoliceVC*)notBoundVC{
    if (_notBoundVC == nil) {
        _notBoundVC = [[UnusualPoliceVC alloc] initWithModel:self.equipModel];
    }
    return _notBoundVC;
}

-(OperationVC*)operVC{
    if (_operVC == nil) {
        _operVC = [[OperationVC alloc] initWithModel:self.equipModel];
    }
    return _operVC;
}

//ZJScrollViewDelegate
- (NSInteger)numberOfChildViewControllers{
    return 3;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    if (index == 0) {
        return self.familyVC;
    }else if (index == 1){
        return self.notBoundVC;
    }else if (index == 2){
        return self.operVC;
    }
    return nil;
}

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
    return NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
